<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>ES6class继承</title>
</head>
<body>
  <script>
    class Person {
      constructor (name) {
        this.name  = name;
      }
      say () {
        console.log('teacher say', this.name);
      }
    }

    class Student extends Person {
      constructor(name, age) {
        super(name); // 在子类中使用this之前必须需要调用super()
        this.age = age;
      }
      // 会重写父类原型对象上的方法
      // say () {
      //   console.log('student say', this.name);
      // }
      cry () {
        console.log('student cry', this.name, this.age);
      }
    }

    const student = new Student('student', 20);
    console.log(student.say());
    console.log(student.cry());
  </script>
</body>
</html>